package com.yzq.authorization.server.controller;

import com.yzq.authorization.server.constants.RedisConstants;
import com.yzq.authorization.server.model.Result;
import com.yzq.authorization.server.support.RedisOperator;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: yangjie.deng@resico.cn
 * @since: 2024-01-31 11:42:53
 * @version: v1.0.0
 * @describe:
 */
@RestController
@RequiredArgsConstructor
public class SmsController {

    private final RedisOperator<String> redisOperator;

    @GetMapping("/smsCaptcha")
    public Result<String> smsCaptcha(String phone) {
        // 示例项目，固定1234
        String smsCaptcha = "1234";
        // 存入缓存中，5分钟后过期
        redisOperator.set((RedisConstants.SMS_CAPTCHA_PREFIX_KEY + phone), smsCaptcha, RedisConstants.DEFAULT_TIMEOUT_SECONDS);

        return Result.success("获取短信验证码成功.", smsCaptcha);
    }
}
